<style>
	body{
		background: #f5f5f5;
	}
	#area2{
		font-size: .8rem;
	}
</style>
<link rel="stylesheet" href="__PUBLIC__/home/js/mobileSelect/css/mobileSelect.css">
<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">编辑地址</p>
	{if !$redirect_url}
	<a id="delBtn" href="javascript:void(0);" class="a3">删除</a>
	{/if}
</div>
<div class="kong1"></div>
<div class="neng_section2">
	<div class="neng_section2_1 neng_section2_1x">
		<form action="">
			<input type="hidden" name="area_position" value="{$info.area_position}">
			<input type="hidden" name="pro_id" value="{$info.pro_id}">
			<input type="hidden" name="city_id" value="{$info.city_id}">
			<input type="hidden" name="area_id" value="{$info.area_id}">
			<div class="f1 clearfix">
				<p class="p1">收货人</p>
				<input type="text" name="name" class="input1 input_plc" placeholder="请输入收货人姓名" autocomplete="off" value="{$info.name}">
			</div>
			<div class="f1 clearfix">
				<p class="p1">手机号码</p>
				<input type="tel" maxlength="11" name="mobile" class="input1 input_plc" placeholder="请输入手机号码" autocomplete="off" value="{$info.mobile}">
			</div>
			<div class="f1 clearfix">
				<p class="p1">所在地区</p>
				<!--				<input type="text" class="input1 input_plc" placeholder="请选择所在地区" readonly id="area2">-->
				<span readonly id="area2" class="input1 input_plc">{$info.pro} {$info.city} {$info.area}</span>
			</div>
			<div class="f1 clearfix">
				<p class="p1">详细地址</p>
				<input type="text" name="address" class="input1 input_plc" placeholder="请输入详细地址" autocomplete="off" value="{$info.address}">
			</div>
			<div class="f1 clearfix">
				<p class="p3">设为默认</p>
				<div class="swi">
					<input type="hidden" name="is_def" value="{$info.is_def}">
					<img src="__PUBLIC__/home/images/a50.png" alt="" class="ud1" {if $info['is_def']==1}style="display:block;"{else/}style="display:none"{/if}>
					<img src="__PUBLIC__/home/images/a51.png" alt="" class="im1 ud2" {if $info['is_def']==0}style="display:block;"{else/}style="display:none"{/if}>
				</div>
			</div>
			<div class="sub">
				<button type="button" id="submit">确定</button>
			</div>
		</form>
	</div>
</div>
<script src="__PUBLIC__/home/js/mobileSelect/js/mobileSelect.js"></script>
<script>
	var redirect_url = "{$redirect_url}";
	$(function(){
		$(".ud1").click(function(){
			$(".ud2").show();
			$("input[name='is_def']").val(0);
			$(this).hide();
		})
		$(".ud2").click(function(){
			$(".ud1").show();
			$("input[name='is_def']").val(1);
			$(this).hide();
		})

		$("#submit").click(function () {
			var name = $("input[name=name]").val();
			var mobile = $("input[name=mobile]").val();
			var address = $("input[name=address]").val();
			var is_def = $("input[name=is_def]").val();
			var pro_id = $("input[name=pro_id]").val();
			var city_id = $("input[name=city_id]").val();
			var area_id = $("input[name=area_id]").val();
			var area_position = $("input[name=area_position]").val();

			modal.ajax('',{name:name,mobile:mobile,address:address,is_def:is_def,pro_id:pro_id,city_id:city_id,area_id:area_id,area_position:area_position},function (res) {
				if(res.result_code==0){

					if(redirect_url == "1"){
						modal.msg('修改地址成功');
						setTimeout(function () {
							window.history.back();
						},1000);
					}else if(redirect_url == "2"){
						var address_id = res.data;
						modal.ajax("{:url('Order/changeAddress')}",{address_id:address_id},function (result) {
							if(result.result_code==0){
								modal.msg('新增地址成功');
								setTimeout(function () {
									window.history.back();
								},1000);
							}else{
								modal.msg(result.info);
							}
						},function (e) {
							console.log(e);
						});
					}else{
						modal.msg('新增地址成功');
						setTimeout(function () {
							window.history.back();
						},1000);
					}
				}else{
					modal.msg(res.info);
				}
			});
		})
		$("#delBtn").click(function () {
			var address_id = "{$info.id}";
			modal.confirm('确认删除此收货地址?',function () {
				modal.ajax("{:url('User/delAddress')}",{address_id:address_id},function (res) {
					modal.msg(res.info);
					if(res.result_code==0){
						setTimeout(function () {
							window.history.back();
						},1000);
					}
				});
			});
		});

	})
</script>
<script type="text/javascript">
	var mobileSelect3 = new MobileSelect({
		trigger: '#area2',
		title: '地区选择',
		wheels: [
			{
				data:{$region}
			}
		],
		position:"{$info.area_position}".split(","),
		callback:function(indexArr, data){
			$("input[name='area_position']").val(indexArr.join(","));
			$.each(data, function (i,v) {
				if(i==0){
					$("input[name='pro_id']").val(v.id);
				}
				if(i==1){
					$("input[name='city_id']").val(v.id);
				}
				if(i==2){
					$("input[name='area_id']").val(v.id);
				}
			})
		}
	});
</script>